﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace jsGotoDefinition.VS2010.Helpers
{
    /// <summary>
    /// Object representing the settings for the application as take from an XML document
    /// </summary>
    public class Settings
    {
        XmlDocument xmldoc = new XmlDocument(); 

        /// <summary>
        /// Create a new Settings objects from a path containing an XML file
        /// </summary>
        /// <param name="xmlpath">The path to the XML file</param>
        public Settings(string xmlpath, FindRegExCollection.RegExMode mode) {
            
            xmldoc.Load(xmlpath);
            
            FindRegExCollection = new FindRegExCollection(xmldoc, mode);
            XmlNode stopnode = xmldoc.SelectSingleNode("//settings/stopAfterFindInFirst");
            if (stopnode != null) {
                if (stopnode.InnerText == "true")
                    StopAfterFindInFirst = true;
            }
            
        }


        /// <summary>
        /// A collection of regular expressions that will be used to search for code
        /// </summary>
        public FindRegExCollection FindRegExCollection { get; set; }

        /// <summary>
        /// Defines whether or not a search should stop if potential definitions are found in the current file
        /// </summary>
        public bool StopAfterFindInFirst { get; set; }

        public void ChangeFindRegExMode(FindRegExCollection.RegExMode mode) {
            FindRegExCollection = new FindRegExCollection(xmldoc, mode);
        }
    }
}
